/*
 * @lc app=leetcode.cn id=594 lang=cpp
 *
 * [594] 最长和谐子序列
 */

// @lc code=start
class Solution
{
public:
  int findLHS(vector<int>& nums)
  {
    unordered_map<int, int> m;
    for (int& num : nums)
      m[num]++;
    int lhs = 0;
    for (auto itr = m.begin(); itr != m.end(); ++itr) {
      int greater = itr->first + 1;
      if (m.find(greater) != m.end())
        lhs = max(lhs, itr->second + m[greater]);
    }
    return lhs;
  }
};
// @lc code=end
